package com.compass.doctor.ui.home.viewmodel

import androidx.lifecycle.MutableLiveData
import com.compass.framework.model.Doctor
import com.compass.framework.model.ScreenTag
import com.compass.framework.toast.TipsToast
import com.compass.network.callback.IApiErrorCallback
import com.compass.network.manager.ApiManager
import com.compass.network.viewmodel.BaseViewModel

/**
 * Description： 医生viewModel
 * Date:2024/1/8 9:41
 */
class DoctorViewModel : BaseViewModel() {
    val doctorLiveData: MutableLiveData<MutableList<Doctor>?> = MutableLiveData()
    val departmentLiveData: MutableLiveData<MutableList<ScreenTag>> = MutableLiveData()
    val positionLiveData: MutableLiveData<MutableList<ScreenTag>> = MutableLiveData()
    var transferLiveData= MutableLiveData<Boolean>()


    /**
     * key:关键词
     * position:职称编码
     * department: 科室编码
     */
    fun getDoctorList(
        pageNo: Int,
        pageSize: Int = 10,
        key: String?,
        position: String?,
        department: String?,
        type: Int,
        orderId: String?=""
    ) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.getDoctorList(pageNo, pageSize, key, position, department, type,orderId)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
                doctorLiveData.value = null
            }
        }, successBlock = {
            if (it == null || it.list.isNullOrEmpty()) {
                doctorLiveData.value = null
            } else {
                doctorLiveData.value = it.list
            }
        })

    }


    fun consultationTransfer(id: String?, doctorId: String) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.consultationTransfer(id, doctorId)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
            }
        }, successBlock = {
            it?.let {
                transferLiveData.value = true
            }

        })

    }


    fun getPositionList() {
        launchUIWithResult(responseBlock = {
            ApiManager.api.getPositionList()
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
            }
        }, successBlock = {
            it?.let {
                positionLiveData.value = it
            }
        })

    }

    fun getDepartmentList() {
        launchUIWithResult(responseBlock = {
            ApiManager.api.getDepartmentList()
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
            }
        }, successBlock = {
            it?.let {
                departmentLiveData.value = it
            }
        })

    }
}